package com.hzit.bootstrap;

import com.hzit.content.ContentApplication;
import com.hzit.gateway.GatewayApplication;
import com.hzit.user.UserApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication(exclude = {
    DataSourceAutoConfiguration.class,
    DataSourceTransactionManagerAutoConfiguration.class
})
public class HzitApplication {
    public static void main(String[] args) {
        // 启动网关服务
        ConfigurableApplicationContext gatewayContext = new SpringApplication(GatewayApplication.class)
            .run("--spring.config.location=classpath:/gateway.yml",
                "--spring.config.name=gateway",
                "--server.port=9000");

        // 启动内容服务
        ConfigurableApplicationContext contentContext = new SpringApplication(ContentApplication.class)
            .run("--spring.config.location=classpath:/content.yml",
                "--spring.config.name=content",
                "--server.port=9001");

        // 启动用户服务
        ConfigurableApplicationContext userContext = new SpringApplication(UserApplication.class)
            .run("--spring.config.location=classpath:/user.yml",
                "--spring.config.name=user",
                "--server.port=9002");

        // 添加关闭钩子
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            userContext.close();
            contentContext.close();
            gatewayContext.close();
        }));
    }
} 